<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column label="菜单图标">
        <template slot-scope="scope">
          <div>
            <i :class="scope.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="success" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="info" @click="edit(scope.row.id)">编 辑</el-button>
            <el-button type="primary" @click="del(scope.row.id)">删 除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {menuDel} from "../../../request/api"
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      list: "menu/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncList: "menu/asyncList",
    }),
    // 点击删除
    del(id) {
      console.log(id);
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
          menuDel({ id: id }).then((res) => {
            if (res.data.code == 200) {
              // 成功的提示窗
              successAlert(res.data.msg);
              // 刷新列表数据
              this.asyncList();
            } else {
              // 失败的提示窗
              warningAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          warningAlert("已取消删除");
        });
    },
    // 点击编辑
    edit(id){
      // 通知父组件，我点了编辑
      this.$emit("edit",id)
    }
  },
  mounted() {
    // 页面一进来就请求列表数据
    this.asyncList();
  },
};
</script>
<style scoped>
</style>